class Solution(object):
    def dayOfTheWeek(self, day, month, year):
        week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
        base = 4
        def judge(y):
            if y % 4 != 0:
                return False
            else:
                if y % 100 == 0:
                    if y % 400 == 0:
                        return True
                    else:
                        return False
                else:
                    return True

        count = 0
        for y in range(1971, year):
            if judge(y):
                count += 366
            else:
                count += 365

        for m in range(1, month):
            if m in {1, 3, 5, 7, 8, 10, 12}:
                count += 31
            else:
                if m in {4, 6, 9, 11}:
                    count += 30
                else:
                    if judge(year):
                        count += 29
                    else:
                        count += 28
        count += day
        return week[(count + base) % 7]


data = Solution()
day = 31
month = 8
year = 2019
print(data.dayOfTheWeek(day, month, year))
